
package com.base.webapp.persist;

import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;


public interface Persistence {

	public EntityManager getEntityManager();
	
	public void openPessimisticLock();

	public void closePessimisticLock();

	public <T> List<T> find(Class<T> modelClass);

	public <T> T find(Class<T> modelClass, Object primaryKey);

	public <T> List<T> find(Class<T> modelClass, String fieldName, Object fieldValue);

	public <T> List<T> findPage(Class<T> modelClass, String fieldName, Object fieldValue, String orderField,
			boolean asceding, Integer pageStart, Integer pageSize);

	public <T> T findSingle(Class<T> modelClass, String fieldName, Object fieldValue);

	public <T> List<T> find(Class<T> modelClass, Map<String, Object> feildValues, Map<String, Boolean> feildAscendings);

	public <T> List<T> find(Class<T> modelClass, Map<String, Object> feildValues, Map<String, Boolean> feildAscendings,
			Integer limitSize);

	public <T> List<T> find(Class<T> modelClass, Map<String, Object> feildValues, Map<String, Boolean> feildAscendings,
			Integer pageNum, Integer pageSize);

	public <T> List<T> findLike(Class<T> modelClass, String fieldName, Object fieldValue);

	public <T> List<T> findOrder(Class<T> modelClass, String feildName, boolean ascending);

	public <T> T findSingle(Class<T> modelClass, Map<String, Object> feildValues);

	public <T> T findLastest(Class<T> modelClass, String timeFieldName, String fieldName, Object fieldValue);

	public <T> T findLastest(Class<T> modelClass, String timeFieldName, Map<String, Object> feildValues);

	/**
	 * sql中的参数以通配符 ? 的形式
	 */
	public <T> List<T> findBySqlWithPage(Class<T> modelClass, Integer pageStart, Integer pageSize, String sql,
			Object... args);

	public <T> List<T> findByNativeSql(Class<T> modelClass, String sql, Object... args);

	public <T> List<T> findByNativeSql(String sql, Object... args);

	public <T> T findSingleByNativeSql(Class<T> modelClass, String sql, Object... args);

	public <T> T findSingleByNativeSql(String sql, Object... args);

	/**
	 * sql中的参数以通配符 ? 的形式
	 */
	public <T> List<T> findBySql(Class<T> modelClass, String sql, Object... args);

	/**
	 * sql语句中的参数 以 :key 的形式
	 */
	public <T> List<T> findBySqlWithMap(Class<T> modelClass, String sql, Map<String, Object> args);

	public <T> T findSingleBySql(Class<T> modelClass, String sql, Object... args);

	public <T> boolean exist(Class<T> modelClass, String fieldName, Object fieldValue);

	public <T> boolean exist(Class<T> modelClass, Map<String, Object> feildValues);

	public void save(Object model);

	public <T> long numberOf(Class<T> modelClass, String fieldName, Object fieldValue);

	public <T> long numberOf(Class<T> modelClass, Map<String, Object> feildValues);

	public <T> Long numberBySqlOf(String sql, Object... args);

	public <T> boolean delete(Class<T> modelClass, String fieldName, Object fieldValue);

	public <T> boolean delete(Class<T> modelClass, Object primaryKey);

	public boolean delete(Object model);

	public <T> List<T> findLimitRows(String sql, int rowsNumLimit, Object... args);

	public <T> List<T> findBySql(String sql, Object... args);

	public <T> List<T> findBySqL(Integer start, Integer size, String sql, Object... args);

	public void detatch(Object o);

	public <T> List<T> findPage(Class<T> modelClass, String fieldName, Object fieldValue, Integer pageStart,
			Integer pageSize);


}
